import sympy as sp

# 定义符号变量
x = sp.symbols('x')

# 面积微元 dA = (x/2 + 2 - x**2/4)
dA = x/2 + 2 - x**2/4

# 总面积 A
A = sp.integrate(dA, (x, -2, 4))

# 关于 y 轴的静矩 M_y = ∫ x * dA dx
M_y = sp.integrate(x * dA, (x, -2, 4))

# 关于 x 轴的静矩 M_x = (1/2) * ∫ [ (上曲线)^2 - (下曲线)^2 ] dx
# 上曲线: y_top = x/2 + 2, 下曲线: y_bottom = x**2/4
M_x = sp.Rational(1, 2) * sp.integrate(( (x/2 + 2)**2 - (x**2/4)**2 ), (x, -2, 4))

# 形心坐标
X = M_y / A
Y = M_x / A

print("总面积 A =", A)
print("静矩 M_y =", M_y)
print("静矩 M_x =", M_x)
print("形心坐标 (X, Y) =", (X, Y))
print("形心坐标数值化:", (float(X), float(Y)))
